package com.css.zfzx.fwsjcj.modules.taskmanage.taskfrom.export;

import cn.afterturn.easypoi.excel.entity.ExportParams;
import com.css.zfzx.fwsjcj.commen.util.EasyPoiExcelUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author leon
 * @Title:
 * @Description:
 * @date 2020/7/21 10:01
 */
@RestController
@RequestMapping("fw")
public class Export {

    @GetMapping("/excel")
    public void export(HttpServletResponse response) {
        //模拟从数据库获取需要导出的数据
        List<Person> personList = new ArrayList<>();
        Person person1 = new Person("路飞", "10", new Date(), 1);
        Person person2 = new Person("娜美", "20", new Date(),0);
        Person person3 = new Person("王生", "22", new Date(),1);
        personList.add(person1);
        personList.add(person2);
        personList.add(person3);
        //导出操作
        ExportParams exportParams = new ExportParams();
        exportParams.setSheetName("我是sheet名字");
        // 生成workbook 并导出
        EasyPoiExcelUtil.exportExcel(personList, "学生信息统计", "学生信息", Person.class, "学生信息.xls", response);
    }

}
